package test;
import java.util.Scanner;
public class qqq1 {
    static int min = 10000000;
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        int N=scan.nextInt();
        int M=scan.nextInt();
        int[] a= new int[M+1];
        for (int i = 0;i<N;i++){
            int n = scan.nextInt();
            a[n]=1;
        }

        for(int k =1;k<=M;k++){
            int x=k;
            for(int h=1;h<=M;h++){
                int sum=0;
                if(k+h==10){
                    x=k+h;
                }else{
                    x=(k+h)%10;
                }
                if(a[x]==1){
                    sum++;
                }
                if(sum==N){
                    if(sum<min){
                        min=sum;
                    }
                }
            }
            for(int h=1;h<=M;h++){
                int sum=0;
                if(k-h<=0){
                    x=k-h+M;
                }else{
                    x=(k-h)%10;
                }
                if(a[x]==1){
                    sum++;
                }
                if(sum==N){
                    if(sum<min){
                        min=sum;
                    }
                }
            }
        }
        System.out.println(min);
        scan.close();
    }
}
